import http from '@/config/request';
 
export default {
  // 获取公告列表
  getAnnouncementList(params) {
    // 直接拼接URL参数
    let url = '/admin/announcement/list';
    if (params) {
      const { current, size, title, status, startDate, endDate } = params;
      url += `?current=${current}&size=${size}`;
      if (title) {
        url += `&title=${encodeURIComponent(title)}`;
      }
      if (status) {
        url += `&status=${status}`;
      }
      if (startDate) {
        url += `&startDate=${startDate}`;
      }
      if (endDate) {
        url += `&endDate=${endDate}`;
      }
    }
    return http.get(url);
  },
  
  // 获取公告详情
  getAnnouncementDetail(id) {
    return http.get(`/admin/announcement/detail?id=${id}`);
  },
  
  // 添加公告
  addAnnouncement(data) {
    return http.post('/admin/announcement/create', data);
  },
  
  // 编辑公告
  updateAnnouncement(data) {
    return http.put('/admin/announcement/update', data);
  },
  
  // 删除公告
  deleteAnnouncement(id) {
    return http.delete(`/admin/announcement/delete?id=${id}`);
  },
  
  // 查看公告阅读状态
  getReadStatus(announcementId, status) {
    let url = `/admin/announcement/read-status?announcementId=${announcementId}`;
    if (status) {
      url += `&status=${status}`;
    }
    return http.get(url);
  }
};